class Solution {
public:
    vector<vector<pair<int,int>>> g;
    vector<bool> vis;
    int ans = INT_MAX;
    int m;

    void dfs(int cur)
    {
        for(int i = 0;i < g[cur].size();i++)
        {
            ans = min(ans,g[cur][i].second);
            int next = g[cur][i].first;
            if(vis[next]) continue;
            vis[next] = true;
            dfs(next);
        }
    }

    int minScore(int n, vector<vector<int>>& roads) {
        vis.resize(n + 1,false);
        m = n;
        g.resize(n + 1);

        for(auto& e : roads)
        {
            g[e[0]].push_back({e[1],e[2]});
            g[e[1]].push_back({e[0],e[2]});
        }
        vis[1] = true;
        dfs(1);
        return ans;
    }
};

//遍历所有的点也就可以遍历所有的边，所以无需vis[next] = false;
//每条边都需要更新答案，不能因为next被遍历过了就不更新这条边的答案